package client.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;

import client.R;

/**
 * 项目名称：client.dialog
 * 创建人:LuoFG
 * 创建时间:2021/9/15  10:32
 * 描述:
 * 作用:
 */
public class DialogLoading  {
    private Context mContext;
    private Dialog dialog;
    private View contentView;


    public interface IBack{
        void back();
    }




    public DialogLoading(Context mContext) {
        this.mContext = mContext;
        initView(mContext);
    }

    /**
     * dialog初始化
     *
     * @param mContext
     */
    private void initView(Context mContext) {
        dialog = new Dialog(mContext, R.style.dialog_style);
        contentView= LayoutInflater.from(mContext).inflate(R.layout.bga_pp_dialog_loading, null);
        dialog.setContentView(contentView);
        Window win = dialog.getWindow();
        win.setGravity(Gravity.CENTER);
        //win.setWindowAnimations(R.style.DialogAnimationFade);
        win.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);

    }






    /**
     * 对话框显示
     */
    public DialogLoading show() {
        try {
            if (mContext == null) {
                return this;
            }

            if (dialog == null || dialog.isShowing()) {
                return this;
            }
            dialog.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }


    /**
     * 对话框关闭
     */
    public DialogLoading dismiss() {
        try {
            if (mContext == null) {
                return this;
            }

            if (dialog != null && dialog.isShowing()) {
                dialog.dismiss();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this;
    }



}

